package main

import (
	"fmt"
	"strconv"
)

func main() {
	// strconv 的用法
	StringToInt()
	IntToString()
}

// 字符串转数字
func StringToInt() {
	// string to int32
	a := "1"
	aInt, err := strconv.ParseInt(a, 10, 32)
	fmt.Println(aInt, err)

	// string to float32
	b, err := strconv.ParseFloat("1.2", 32)
	fmt.Println(b, err)

	// string to uint64
	c, err := strconv.ParseUint("12", 10, 32)
	fmt.Println(c, err)

	// stirng to int
	d, err := strconv.Atoi("23")
	fmt.Println(d, err)
}

// 数字装字符串
func IntToString() {
	// int64 to string
	a := fmt.Sprintf("%d", 32)
	fmt.Println(a)

	// int to string
	b := strconv.Itoa(32)
	fmt.Println(b)

	// uint64 to string
	c := strconv.FormatUint(21, 10)
	fmt.Println(c)

}
